﻿namespace MSSqlSchemaDoc.Core.DataStructures
{
    using System;
    using System.Collections.ObjectModel;
    using System.Xml.Serialization;

    /// <summary>
    /// Represents a column in a database object.
    /// </summary>
    [Serializable()]
    public class Column
    {
        /// <summary>
        /// Gets or sets the name of the column.
        /// </summary>
        [XmlAttribute()]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the ID of the columns (local to the table).
        /// </summary>
        [XmlIgnore()]
        public int ColumnId { get; set; }

        /// <summary>
        /// Gets or sets the ID of the table containing the column.
        /// </summary>
        [XmlIgnore()]
        public int ParentObjectId { get; set; }

        /// <summary>
        /// Gets or sets the data type of the column.
        /// </summary>
        [XmlElement()]
        public DataType DataType { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column can have a null value or not.
        /// </summary>
        [XmlElement()]
        public bool IsNullable { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column has a default value.
        /// </summary>
        [XmlElement()]
        public bool HasDefault { get; set; }

        /// <summary>
        /// Gets or sets the default value of the column, if the column HAS a default. See the HasDefault property.
        /// </summary>
        [XmlElement()]
        public string DefaultValue { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column is an identity column.
        /// </summary>
        [XmlElement()]
        public bool IsIdentity { get; set; }
        
        /// <summary>
        /// Gets or sets the settings of the identity column - if present.
        /// </summary>
        [XmlElement()]
        public IdentityColumn IdentitySettings { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column value is computed.
        /// </summary>
        [XmlElement()]
        public bool IsComputed { get; set; }

        /// <summary>
        /// Gets or sets the settings of the computed column - if present.
        /// </summary>
        [XmlElement()]
        public ComputedColumn ComputationSettings { get; set; }

        /// <summary>
        /// Gets or sets the collation of the column.
        /// </summary>
        [XmlElement(IsNullable = true)]
        public string Collation { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column is ansi padded.
        /// </summary>
        [XmlElement()]
        public bool IsAnsiPadded { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column is a row guid.
        /// </summary>
        [XmlElement()]
        public bool IsRowGuid { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column is part of a primary or unique key.
        /// </summary>
        [XmlElement()]
        public ColumnKeyConstraint ColumnKeyConstraint { get; set; }

        /// <summary>
        /// Gets or sets a collection of indexes of which the column is a member.
        /// </summary>
        [XmlArray()]
        public Collection<IndexMember> IndexMembers { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the column is part of a full text index.
        /// </summary>
        [XmlElement()]
        public bool IsFullTextIndexed { get; set; }

        /// <summary>
        /// Gets or sets a collection of foreign key references.
        /// </summary>
        [XmlArray()]
        public Collection<ForeignKeyReference> ForeignKeyReferences { get; set; }
    }
}
